<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){										
            $("#Form").validate({
				ignore: "",
                rules: {
					"movie_type_id[]": "required",
					media_type_id: "required",
					letters: "required",
					movie_name: "required",	
					movie_tag: "required"
                },
                showErrors: function(errorMap, errorList){
                    var messages='';
                    for (var i = 0; i < errorList.length; i++) {					
                        messages += '- '+errorList[i].message+'\n';
                    }
                    if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
                    //this.defaultShowErrors();
                } ,
                submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					if(queueSize > 0){
						$('#file_upload').uploadifyUpload();
					} else { success_file = true; }
					if(queueSize2 > 0){
						$('#file_upload2').uploadifyUpload();
					} else { success_file2 = true; }
					if(queueSize3 > 0){
						$('#file_upload3').uploadifyUpload();
					} else { success_file3 = true; }
					if(queueSize4 > 0){
						$('#file_upload4').uploadifyUpload();
					} else { success_file4 = true; }									
					var interval = setInterval(function() {
					    if (success_file && success_file2 && success_file3 && success_file4) {
					        clearInterval(interval);
							//Send Form
					        document.forms["Form"].submit();
					    }
					}, 100);
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,					
                messages: {
					"movie_type_id[]": "<?php echo lang('movie_type');?>",
					media_type_id: "<?php echo lang('media_type');?>",
					genre_id: "<?php echo lang('genre');?>",
					letters: "<?php echo lang('letters');?>",
					movie_name: "<?php echo lang('movie_name');?>",
					movie_tag: "<?php echo lang('movie_tag');?>",
					file_upload2: {
						file_upload2_valid: "<?php echo lang('movie_file');?>"
					}								
                }
            });	
			
            /*Images Upload*/
            var queueSize = 0;		
            var imgname= new Array();
			var success_file = false;					
            $('#file_upload').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : true,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store',
					    name: 'uploadify_store',
						value: imgname
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file=true;
                },			
                'onSelectOnce' : function (event,data) {
                    queueSize = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize = data.fileCount;
                }						
            });	

            /*File Upload*/
            var queueSize2 = 0;		
            var imgname2= new Array();
			var success_file2 = false;					
            $('#file_upload2').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.mp4;*.MP4',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : false,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname2.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store2',
					    name: 'uploadify_store2',
						value: imgname2
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file2=true;
                },			
                'onSelectOnce' : function (event,data) {
                    queueSize2 = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize2 = data.fileCount;
                }						
            });
			
            /*File Upload*/
            var queueSize3 = 0;		
            var imgname3= new Array();
			var success_file3 = false;					
            $('#file_upload3').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.mp4;*.MP4',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : false,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname3.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store3',
					    name: 'uploadify_store3',
						value: imgname3
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file3=true;
                },			
                'onSelectOnce' : function (event,data) {
                    queueSize3 = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize3 = data.fileCount;
                }						
            });
			
            /*File Upload*/
            var queueSize4 = 0;		
            var imgname4= new Array();
			var success_file4 = false;					
            $('#file_upload4').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.mp4;*.MP4',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : false,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname4.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store4',
					    name: 'uploadify_store4',
						value: imgname4
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file4=true;
                },			
                'onSelectOnce' : function (event,data) {
                    queueSize4 = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize4 = data.fileCount;
                }						
            });
			
			//ColorBox Image
			$('a[rel="gallery"]').colorbox();
			
			//DateTime Picker
			$('.datetime').datetimepicker({
				dateFormat:'dd/mm/yy',
				timeFormat:'hh:mm',
				separator:' ',
				changeMonth : true,
				changeYear : true,
				yearRange: '-10y:+5y',
				showHour: true,		
				showMinute: true,
				showTime: true		
			});
			
			//Drag && Drop
			$( ".listImages" ).sortable(
				{
					connectWith: "li",
					cursor: 'move',
					handle: 'img',
					placeholder: 'placeholder',
					forcePlaceholderSize: true,
					opacity: 0.4,
					update: function(event, ui)
					{
						//do process
						var data = $(this).sortable('serialize');
						$.ajax(
							{
								type:'post',
								url:web_path+'movie/content_management/ajax_update_image',
								data:data
							});
					}
				}).disableSelection();	
        });
    })(jQuery);
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>	
						<tr>
							<th scope="row"><?php echo lang('is_publish');?></th>
							<td>
								<input type="radio" name="is_publish" value="1" <?php echo ($dataResult->is_publish == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" <?php echo ($dataResult->is_publish == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('movie_publish_date');?></th>
							<td><input type="text" name="movie_publish_date" id="movie_publish_date" class="medium-text datetime" readonly="readonly" value="<?php echo (!empty($dataResult->movie_publish_date) ? date('d/m/Y',strtotime($dataResult->movie_publish_date)):'');?>"/></td>
						</tr>											
						<tr>
							<th scope="row"><?php echo lang('movie_type');?></th>
							<td>
								<?php if(!empty($dataMovieType)):?> 
									<ul class="listItemsHorizontal">
										<?php foreach($dataMovieType as $value):?>
										<li>
											<input type="checkbox" name="movie_type_id[]" value="<?php echo $value->movie_type_id;?>" <?php echo (in_array($value->movie_type_id,$dataMovieTypeRelate) ? 'checked="checked"':'');?>/> <?php echo $value->movie_type_name;?>
										</li>
										<?php endforeach;?>
									</ul>
								<?php endif;?>
							</td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('media_type');?></th>
							<td>
								<select id="media_type_id" name="media_type_id" class="medium-text">
									<option value=""><?php echo lang('select_option');?></option>
									<?php foreach($dataMediaType as $value):?>
										<option value="<?php echo $value->media_type_id;?>" <?php echo ($dataResult->media_type_id == $value->media_type_id ? 'selected="selected"':'');?>><?php echo $value->media_type_name;?></option>
									<?php endforeach;?>
								</select>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_video_clip');?></th>
							<td>
								<input type="radio" name="is_video_clip" value="1" <?php echo ($dataResult->is_video_clip == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_video_clip" value="0" <?php echo ($dataResult->is_video_clip == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_new_released');?></th>
							<td>
								<input type="radio" name="is_show_new_released" value="1" <?php echo ($dataResult->is_show_new_released == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_new_released" value="0" <?php echo ($dataResult->is_show_new_released == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('letters');?></th>
							<td><input type="text" name="letters" id="letters" class="small-text" maxlength="1" value="<?php echo $dataResult->letters;?>"/></td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('movie_name');?></th>
							<td><input type="text" name="movie_name" id="movie_name" class="regular-text" value="<?php echo htmlspecialchars($dataResult->movie_name, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('movie_description');?></th>
							<td><?php echo display_ckeditor('movie_description',''.$dataResult->movie_description.'',array('toolbar' => 'Medium','skin' => 'v2','width' => '550px','height' => '200px'),false); ?></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('movie_author');?></th>
							<td><input type="text" name="movie_author" id="movie_author" class="regular-text" value="<?php echo htmlspecialchars($dataResult->movie_author, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('movie_actor');?></th>
							<td><input type="text" name="movie_actor" id="movie_actor" class="regular-text" value="<?php echo htmlspecialchars($dataResult->movie_actor, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('movie_tag');?></th>
							<td><input type="text" name="movie_tag" id="movie_tag" class="regular-text" value="<?php echo htmlspecialchars($dataResult->movie_tag, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('movie_image');?></th>
							<td>
								<?php
								if(!empty($dataMovieImage)):?>
								<ul class="listImages">
									<?php foreach($dataMovieImage as $value):?>
									<li id="movie_image_id_<?php echo $value->movie_image_id;?>">
										<div>
											<a href="<?php echo image_asset_url('../uploads/movie/images/original/'.$value->movie_file_name.'.'.$value->movie_file_ext);?>" rel="gallery">
												<?php echo image_asset('../uploads/movie/images/120x120/'.$value->movie_file_name.'.'.$value->movie_file_ext,'',array('width' => 120,'height'=> 120));?>
											</a>
										</div>
										<a href="javascript:void(0);" title="<?php echo image_asset_url('../uploads/movie/images/original/'.$value->movie_file_name.'.'.$value->movie_file_ext);?>" onmouseOver="javascript:toClipboard(this)" class="tools wishlist"></a>
										<a href="<?php echo base_url();?>movie/content_management/ajax_delete_image/<?php echo $value->movie_image_id;?>" class="tools delete deleteImage"></a>
									</li>
									<?php endforeach;?>
								</ul>
								<?php endif;?>
								<input type="file" name="file_upload" id="file_upload"/>
							</td>
						</tr>								
						<tr>
							<th scope="row"><?php echo lang('movie_file');?></th>
							<td>
								<?php if($dataResult->movie_file_name1):?>
									<div>
										<iframe src="<?php echo base_url('movie_player/'.$dataResult->movie_id.'/1');?>" width="425" height="300" scrolling="no"></iframe><br />
										<a href="<?php echo base_url();?>movie/content_management/ajax_delete_media/<?php echo $dataResult->movie_id;?>?field[]=movie_file_name1&amp;field[]=movie_file_ext1" class="tools delete deleteImage response-links"></a>
									</div><br />
								<?php endif;?>
								<input type="file" name="file_upload2" id="file_upload2"/>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('movie_file');?></th>
							<td>
								<?php if($dataResult->movie_file_name2):?>
									<div>
										<iframe src="<?php echo base_url('movie_player/'.$dataResult->movie_id.'/2');?>" width="425" height="300" scrolling="no"></iframe><br />
										<a href="<?php echo base_url();?>movie/content_management/ajax_delete_media/<?php echo $dataResult->movie_id;?>?field[]=movie_file_name2&amp;field[]=movie_file_ext2" class="tools delete deleteImage response-links"></a>
									</div><br />
								<?php endif;?>
								<input type="file" name="file_upload3" id="file_upload3"/>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('movie_file');?></th>
							<td>
								<?php if($dataResult->movie_file_name3):?>
									<div>
										<iframe src="<?php echo base_url('movie_player/'.$dataResult->movie_id.'/3');?>" width="425" height="300" scrolling="no"></iframe><br />
										<a href="<?php echo base_url();?>movie/content_management/ajax_delete_media/<?php echo $dataResult->movie_id;?>?field[]=movie_file_name3&amp;field[]=movie_file_ext3" class="tools delete deleteImage response-links"></a>
									</div><br />
								<?php endif;?>
								<input type="file" name="file_upload4" id="file_upload4"/>
							</td>
						</tr>												
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_edit');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->